{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f7059800",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using data directory: /Users/hbu/.bokeh/data\n",
      "Skipping 'CGM.csv' (checksum match)\n",
      "Skipping 'US_Counties.zip' (checksum match)\n",
      "Skipping 'us_cities.json' (checksum match)\n",
      "Skipping 'unemployment09.csv' (checksum match)\n",
      "Skipping 'AAPL.csv' (checksum match)\n",
      "Skipping 'FB.csv' (checksum match)\n",
      "Skipping 'GOOG.csv' (checksum match)\n",
      "Skipping 'IBM.csv' (checksum match)\n",
      "Skipping 'MSFT.csv' (checksum match)\n",
      "Skipping 'WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip' (checksum match)\n",
      "Skipping 'gapminder_fertility.csv' (checksum match)\n",
      "Skipping 'gapminder_population.csv' (checksum match)\n",
      "Skipping 'gapminder_life_expectancy.csv' (checksum match)\n",
      "Skipping 'gapminder_regions.csv' (checksum match)\n",
      "Skipping 'world_cities.zip' (checksum match)\n",
      "Skipping 'airports.json' (checksum match)\n",
      "Skipping 'movies.db.zip' (checksum match)\n",
      "Skipping 'airports.csv' (checksum match)\n",
      "Skipping 'routes.csv' (checksum match)\n",
      "Skipping 'haarcascade_frontalface_default.xml' (checksum match)\n"
     ]
    }
   ],
   "source": [
    "import bokeh.sampledata\n",
    "bokeh.sampledata.download()\n",
    "#show(p)  # open a browser"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f2b00913",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1635\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  const force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  const JS_MIME_TYPE = 'application/javascript';\n",
       "  const HTML_MIME_TYPE = 'text/html';\n",
       "  const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  const CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    const script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    const cell = handle.cell;\n",
       "\n",
       "    const id = cell.output_area._bokeh_element_id;\n",
       "    const server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd_clean, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            const id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd_destroy);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    const output_area = handle.output_area;\n",
       "    const output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      const bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      const script_attrs = bk_div.children[0].attributes;\n",
       "      for (let i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      const toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    const events = require('base/js/events');\n",
       "    const OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  const NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    const el = document.getElementById(\"1635\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error(url) {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < css_urls.length; i++) {\n",
       "      const url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < js_urls.length; i++) {\n",
       "      const url = js_urls[i];\n",
       "      const element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n",
       "  const css_urls = [];\n",
       "  \n",
       "\n",
       "  const inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (let i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      const cell = $(document.getElementById(\"1635\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  const force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  const NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    const el = document.getElementById(\"1635\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error(url) {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (let i = 0; i < css_urls.length; i++) {\n      const url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (let i = 0; i < js_urls.length; i++) {\n      const url = js_urls[i];\n      const element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n  const css_urls = [];\n  \n\n  const inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (let i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      const cell = $(document.getElementById(\"1635\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"a297bc34-0c85-41bf-ad7d-aad2b242bb29\" data-root-id=\"1586\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"5e1495a1-3214-4660-b6b5-e94dbe33a8ab\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1595\"}],\"center\":[{\"id\":\"1598\"},{\"id\":\"1602\"}],\"left\":[{\"id\":\"1599\"}],\"renderers\":[{\"id\":\"1621\"},{\"id\":\"1627\"},{\"id\":\"1633\"}],\"title\":{\"id\":\"1615\"},\"toolbar\":{\"id\":\"1609\"},\"toolbar_location\":\"left\",\"width\":1000,\"x_range\":{\"id\":\"1587\"},\"x_scale\":{\"id\":\"1591\"},\"y_range\":{\"id\":\"1589\"},\"y_scale\":{\"id\":\"1593\"}},\"id\":\"1586\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1639\",\"type\":\"AllLabels\"},{\"attributes\":{\"source\":{\"id\":\"1623\"}},\"id\":\"1628\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1591\",\"type\":\"LinearScale\"},{\"attributes\":{\"months\":[0,2,4,6,8,10]},\"id\":\"1658\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"line_alpha\":{\"value\":0.1},\"x0\":{\"field\":\"x0\"},\"x1\":{\"field\":\"x1\"},\"y0\":{\"field\":\"y0\"},\"y1\":{\"field\":\"y1\"}},\"id\":\"1619\",\"type\":\"Segment\"},{\"attributes\":{\"fill_color\":{\"value\":\"#F2583E\"},\"height\":{\"field\":\"height\"},\"width\":{\"value\":43200000},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1630\",\"type\":\"Rect\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#F2583E\"},\"hatch_alpha\":{\"value\":0.2},\"height\":{\"field\":\"height\"},\"line_alpha\":{\"value\":0.2},\"width\":{\"value\":43200000},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1632\",\"type\":\"Rect\"},{\"attributes\":{\"days\":[1,15]},\"id\":\"1656\",\"type\":\"DaysTicker\"},{\"attributes\":{},\"id\":\"1644\",\"type\":\"Selection\"},{\"attributes\":{\"days\":[1,4,7,10,13,16,19,22,25,28]},\"id\":\"1654\",\"type\":\"DaysTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#D5E1DD\"},\"hatch_alpha\":{\"value\":0.2},\"height\":{\"field\":\"height\"},\"line_alpha\":{\"value\":0.2},\"width\":{\"value\":43200000},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1626\",\"type\":\"Rect\"},{\"attributes\":{},\"id\":\"1589\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1642\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1629\"},\"glyph\":{\"id\":\"1630\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1632\"},\"nonselection_glyph\":{\"id\":\"1631\"},\"view\":{\"id\":\"1634\"}},\"id\":\"1633\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"num_minor_ticks\":5,\"tickers\":[{\"id\":\"1650\"},{\"id\":\"1651\"},{\"id\":\"1652\"},{\"id\":\"1653\"},{\"id\":\"1654\"},{\"id\":\"1655\"},{\"id\":\"1656\"},{\"id\":\"1657\"},{\"id\":\"1658\"},{\"id\":\"1659\"},{\"id\":\"1660\"},{\"id\":\"1661\"}]},\"id\":\"1596\",\"type\":\"DatetimeTicker\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1638\"},\"group\":null,\"major_label_policy\":{\"id\":\"1639\"},\"ticker\":{\"id\":\"1600\"}},\"id\":\"1599\",\"type\":\"LinearAxis\"},{\"attributes\":{\"months\":[0,4,8]},\"id\":\"1659\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"source\":{\"id\":\"1617\"}},\"id\":\"1622\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1623\"},\"glyph\":{\"id\":\"1624\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1626\"},\"nonselection_glyph\":{\"id\":\"1625\"},\"view\":{\"id\":\"1628\"}},\"id\":\"1627\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1648\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1638\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1587\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1600\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#F2583E\"},\"hatch_alpha\":{\"value\":0.1},\"height\":{\"field\":\"height\"},\"line_alpha\":{\"value\":0.1},\"width\":{\"value\":43200000},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1631\",\"type\":\"Rect\"},{\"attributes\":{\"tools\":[{\"id\":\"1603\"},{\"id\":\"1604\"},{\"id\":\"1605\"},{\"id\":\"1606\"},{\"id\":\"1607\"}]},\"id\":\"1609\",\"type\":\"Toolbar\"},{\"attributes\":{\"data\":{\"height\":{\"__ndarray__\":\"ANejcD0K8z8AKVyPwvX4PwBSuB6F6/U/AAAAAAAA/D/A9Shcj8ISQADXo3A9Cvc/ALgehetR2D8AUrgehevpP4AUrkfhehBAAAAAAAAAGEAAXI/C9SjcP0AK16NwPRRAAK5H4XoU5j8AAAAAAAAAQAAAAAAAANA/gBSuR+F6AEAAUrgehev5P0AK16NwPRBAABSuR+F61D8ApHA9CtfjPwApXI/C9QJAAArXo3A94j8AuB6F61HIPwBwPQrXo8A/AKRwPQrX6z8=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[25]},\"x\":{\"__ndarray__\":\"AACAp/mza0IAAABznrRrQgAAgD5DtWtCAAAAOHu4a0IAAIADILlrQgAAAM/EuWtCAACAMbO7a0IAAIDI/LxrQgAAgF9GvmtCAACAjdnAa0IAAABZfsFrQgAAgCQjwmtCAAAAHlvFa0IAAIDp/8VrQgAAgIBJx2tCAAAAEcvLa0IAAAAEO9JrQgAAgM/f0mtCAACAZinUa0IAAABgYddrQgAAAPeq2GtCAAAAJT7ba0IAAAC8h9xrQgAAgIcs3WtCAAAAU9Hda0I=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[25]},\"y\":{\"__ndarray__\":\"9ihcj8KNVkD2KFyPwiVXQKRwPQrX21dApHA9CterV0BSuB6F62lYQFK4HoXrEVlApHA9CtdzWED2KFyPwr1XQKRwPQrXU1hAAAAAAADwWEBSuB6F68FZQPYoXI/CVVtA9ihcj8L9WUBcj8L1KIxaQAAAAAAAiFpAUrgehesBVkCkcD0K18NSQFK4HoXroVNAUrgeheuxU0CkcD0K10NRQAAAAAAAKFFAUrgehetJUkD2KFyPwp1RQAAAAAAAmFFApHA9CterUUA=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[25]}},\"selected\":{\"id\":\"1646\"},\"selection_policy\":{\"id\":\"1645\"}},\"id\":\"1623\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"source\":{\"id\":\"1629\"}},\"id\":\"1634\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#D5E1DD\"},\"hatch_alpha\":{\"value\":0.1},\"height\":{\"field\":\"height\"},\"line_alpha\":{\"value\":0.1},\"width\":{\"value\":43200000},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1625\",\"type\":\"Rect\"},{\"attributes\":{},\"id\":\"1646\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1647\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1604\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"months\":[0,1,2,3,4,5,6,7,8,9,10,11]},\"id\":\"1657\",\"type\":\"MonthsTicker\"},{\"attributes\":{},\"id\":\"1643\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1607\",\"type\":\"SaveTool\"},{\"attributes\":{\"base\":24,\"mantissas\":[1,2,4,6,8,12],\"max_interval\":43200000.0,\"min_interval\":3600000.0,\"num_minor_ticks\":0},\"id\":\"1652\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{\"data\":{\"height\":{\"__ndarray__\":\"gOtRuB6FFUAAAAAAAAAKQAAAAAAAAAxAAArXo3A94j8ArkfhehT2PwD2KFyPwu0/oEfhehSuDUCAwvUoXI8GQIDC9ShcjwxAAAAAAAAACEAArkfhehT+PwBSuB6F6/0/gBSuR+F6BEAAAAAAAAD0PwAAAAAAAAZAAFK4HoXr+T8AAAAAAAAUQAAAAAAAAAZAAFyPwvUo5D8AAAAAAAAAQAAAAAAAAPA/gOtRuB6FB0AArkfhehTyPwDXo3A9CgNAAClcj8L1+D8=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[25]},\"x\":{\"__ndarray__\":\"AAAAoTG3a0IAAIBs1rdrQgAAAP1XvGtCAAAAlKG9a0IAAADCNMBrQgAAAPDHwmtCAACAUrbEa0IAAAC1pMZrQgAAAOM3yWtCAACArtzJa0IAAAB6gcprQgAAgEUmy2tCAACAc7nNa0IAAAA/Xs5rQgAAgAoDz2tCAAAA1qfPa0IAAIChTNBrQgAAAJuE02tCAACAlLzWa0IAAIArBthrQgAAgMJP2WtCAACA8OLba0IAAIC1v99rQgAAAIFk4GtCAACATAnha0I=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[25]},\"y\":{\"__ndarray__\":\"pHA9CtdTV0BI4XoUrp9XQEjhehSuN1hAUrgehevpV0CkcD0K14NYQFK4HoXrCVxAwvUoXI96WkBSuB6F6zFaQFK4HoXrKVdApHA9CteDVkCkcD0K19NVQKRwPQrXu1VA9ihcj8LVVUBI4XoUrh9VQEjhehSuL1RApHA9CtcDVEBI4XoUridTQFyPwvUoBFRApHA9Cte7UEAAAAAAAEBRQAAAAAAAkFFA9ihcj8LVUUAAAAAAAJhRQAAAAAAAQFFArkfhehS+UEA=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[25]}},\"selected\":{\"id\":\"1648\"},\"selection_policy\":{\"id\":\"1647\"}},\"id\":\"1629\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"days\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]},\"id\":\"1653\",\"type\":\"DaysTicker\"},{\"attributes\":{\"line_alpha\":{\"value\":0.2},\"x0\":{\"field\":\"x0\"},\"x1\":{\"field\":\"x1\"},\"y0\":{\"field\":\"y0\"},\"y1\":{\"field\":\"y1\"}},\"id\":\"1620\",\"type\":\"Segment\"},{\"attributes\":{\"fill_color\":{\"value\":\"#D5E1DD\"},\"height\":{\"field\":\"height\"},\"width\":{\"value\":43200000},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1624\",\"type\":\"Rect\"},{\"attributes\":{},\"id\":\"1606\",\"type\":\"ResetTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"MSFT Candlestick\"},\"id\":\"1615\",\"type\":\"Title\"},{\"attributes\":{\"axis\":{\"id\":\"1599\"},\"coordinates\":null,\"dimension\":1,\"grid_line_alpha\":0.3,\"group\":null,\"ticker\":null},\"id\":\"1602\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1641\",\"type\":\"DatetimeTickFormatter\"},{\"attributes\":{},\"id\":\"1603\",\"type\":\"PanTool\"},{\"attributes\":{\"months\":[0,6]},\"id\":\"1660\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1595\"},\"coordinates\":null,\"grid_line_alpha\":0.3,\"group\":null,\"ticker\":null},\"id\":\"1598\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1661\",\"type\":\"YearsTicker\"},{\"attributes\":{},\"id\":\"1645\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"base\":60,\"mantissas\":[1,2,5,10,15,20,30],\"max_interval\":1800000.0,\"min_interval\":1000.0,\"num_minor_ticks\":0},\"id\":\"1651\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{\"x0\":{\"field\":\"x0\"},\"x1\":{\"field\":\"x1\"},\"y0\":{\"field\":\"y0\"},\"y1\":{\"field\":\"y1\"}},\"id\":\"1618\",\"type\":\"Segment\"},{\"attributes\":{\"overlay\":{\"id\":\"1608\"}},\"id\":\"1605\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"mantissas\":[1,2,5],\"max_interval\":500.0,\"num_minor_ticks\":0},\"id\":\"1650\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{},\"id\":\"1593\",\"type\":\"LinearScale\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1617\"},\"glyph\":{\"id\":\"1618\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1620\"},\"nonselection_glyph\":{\"id\":\"1619\"},\"view\":{\"id\":\"1622\"}},\"id\":\"1621\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data\":{\"x0\":{\"__ndarray__\":\"AACAp/mza0IAAABznrRrQgAAgD5DtWtCAAAAoTG3a0IAAIBs1rdrQgAAADh7uGtCAACAAyC5a0IAAADPxLlrQgAAgDGzu2tCAAAA/Ve8a0IAAIDI/LxrQgAAAJShvWtCAACAX0a+a0IAAADCNMBrQgAAgI3ZwGtCAAAAWX7Ba0IAAIAkI8JrQgAAAPDHwmtCAACAUrbEa0IAAAAeW8VrQgAAgOn/xWtCAAAAtaTGa0IAAICAScdrQgAAAOM3yWtCAACArtzJa0IAAAB6gcprQgAAgEUmy2tCAAAAEcvLa0IAAIBzuc1rQgAAAD9ezmtCAACACgPPa0IAAADWp89rQgAAgKFM0GtCAAAABDvSa0IAAIDP39JrQgAAAJuE02tCAACAZinUa0IAAICUvNZrQgAAAGBh12tCAACAKwbYa0IAAAD3qthrQgAAgMJP2WtCAAAAJT7ba0IAAIDw4ttrQgAAALyH3GtCAACAhyzda0IAAABT0d1rQgAAgLW/32tCAAAAgWTga0IAAIBMCeFrQg==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[50]},\"x1\":{\"__ndarray__\":\"AACAp/mza0IAAABznrRrQgAAgD5DtWtCAAAAoTG3a0IAAIBs1rdrQgAAADh7uGtCAACAAyC5a0IAAADPxLlrQgAAgDGzu2tCAAAA/Ve8a0IAAIDI/LxrQgAAAJShvWtCAACAX0a+a0IAAADCNMBrQgAAgI3ZwGtCAAAAWX7Ba0IAAIAkI8JrQgAAAPDHwmtCAACAUrbEa0IAAAAeW8VrQgAAgOn/xWtCAAAAtaTGa0IAAICAScdrQgAAAOM3yWtCAACArtzJa0IAAAB6gcprQgAAgEUmy2tCAAAAEcvLa0IAAIBzuc1rQgAAAD9ezmtCAACACgPPa0IAAADWp89rQgAAgKFM0GtCAAAABDvSa0IAAIDP39JrQgAAAJuE02tCAACAZinUa0IAAICUvNZrQgAAAGBh12tCAACAKwbYa0IAAAD3qthrQgAAgMJP2WtCAAAAJT7ba0IAAIDw4ttrQgAAALyH3GtCAACAhyzda0IAAABT0d1rQgAAgLW/32tCAAAAgWTga0IAAIBMCeFrQg==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[50]},\"y0\":{\"__ndarray__\":\"9ihcj8KFV0BI4XoUrtdXQEjhehSut1hASOF6FK5XWEAAAAAAAGBYQFyPwvUoDFhAAAAAAAAAWUAAAAAAAKBZQAAAAAAAEFlAAAAAAADQWEBI4XoUridYQFyPwvUoLFhAAAAAAADgWEAAAAAAAPBYQEjhehSux1lASOF6FK5nWkBI4XoUrjdcQAAAAAAAwFxAAAAAAAAQW0Bcj8L1KNxaQFyPwvUoPFtASOF6FK4nW0AAAAAAABBbQAAAAAAAIFhAAAAAAAAAV0AAAAAAACBWQAAAAAAAAFZASOF6FK5XVkBI4XoUridWQKRwPQrXg1VAAAAAAACQVEAAAAAAAJBUQAAAAAAA4FNAAAAAAAAAU0Bcj8L1KHxUQAAAAAAAYFRASOF6FK73U0AAAAAAAABRQAAAAAAAYFFASOF6FK7HUUBcj8L1KHxRQAAAAAAAwFFAAAAAAACAUkAAAAAAAGBSQKRwPQrXs1FAAAAAAADQUUCkcD0K1/NRQEjhehSu11FAXI/C9SicUUBI4XoUrvdQQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[50]},\"y1\":{\"__ndarray__\":\"XI/C9Sg8VkBI4XoUrsdWQEjhehSud1dASOF6FK6HVkBcj8L1KPxWQAAAAAAAwFZAAAAAAADAV0AAAAAAAOBYQAAAAAAAYFhASOF6FK7HV0Bcj8L1KGxXQAAAAAAAUFdAAAAAAACgV0AAAAAAACBYQAAAAAAAIFhASOF6FK5HWUBI4XoUrqdaQKRwPQrXY1tAXI/C9Sj8WUBI4XoUrpdZQEjhehSuR1pAAAAAAACgWUBI4XoUrgdaQAAAAAAAgFZAXI/C9Sg8VUBI4XoUrndVQOF6FK5HUVVAAAAAAABAVUAAAAAAAIBVQAAAAAAA4FRAAAAAAACwU0AAAAAAAMBTQAAAAAAAUFJAAAAAAABAUkBI4XoUrvdSQEjhehSuh1NAAAAAAABgU0AAAAAAAEBQQEjhehSu51BASOF6FK7XUEBI4XoUrtdQQAAAAAAAEFFAXI/C9SjsUUAAAAAAAGBRQKRwPQrXM1FApHA9CtdTUUBI4XoUrndRQFyPwvUobFFAAAAAAADgUEAAAAAAAHBQQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[50]}},\"selected\":{\"id\":\"1644\"},\"selection_policy\":{\"id\":\"1643\"}},\"id\":\"1617\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1608\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"days\":[1,8,15,22]},\"id\":\"1655\",\"type\":\"DaysTicker\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1641\"},\"group\":null,\"major_label_orientation\":0.7853981633974483,\"major_label_policy\":{\"id\":\"1642\"},\"ticker\":{\"id\":\"1596\"}},\"id\":\"1595\",\"type\":\"DatetimeAxis\"}],\"root_ids\":[\"1586\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"5e1495a1-3214-4660-b6b5-e94dbe33a8ab\",\"root_ids\":[\"1586\"],\"roots\":{\"1586\":\"a297bc34-0c85-41bf-ad7d-aad2b242bb29\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1586"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from math import pi\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "from bokeh.plotting import figure, output_file\n",
    "from bokeh.sampledata.stocks import MSFT\n",
    "\n",
    "from bokeh.io import show,output_notebook\n",
    "\n",
    "df = pd.DataFrame(MSFT)[:50]\n",
    "df[\"date\"] = pd.to_datetime(df[\"date\"])\n",
    "\n",
    "mids = (df.open + df.close)/2\n",
    "spans = abs(df.close-df.open)\n",
    "\n",
    "inc = df.close > df.open\n",
    "dec = df.open > df.close\n",
    "w = 12*60*60*1000 # half day in ms\n",
    "\n",
    "TOOLS = \"pan,wheel_zoom,box_zoom,reset,save\"\n",
    "\n",
    "p = figure(x_axis_type=\"datetime\", tools=TOOLS, plot_width=1000, toolbar_location=\"left\")\n",
    "\n",
    "p.title = \"MSFT Candlestick\"\n",
    "p.xaxis.major_label_orientation = pi/4\n",
    "p.grid.grid_line_alpha=0.3\n",
    "\n",
    "p.segment(df.date, df.high, df.date, df.low, color=\"black\")\n",
    "p.rect(df.date[inc], mids[inc], w, spans[inc], fill_color=\"#D5E1DD\", line_color=\"black\")\n",
    "p.rect(df.date[dec], mids[dec], w, spans[dec], fill_color=\"#F2583E\", line_color=\"black\")\n",
    "\n",
    "#output_file(\"candlestick.html\", title=\"candlestick.py example\")\n",
    "output_notebook()\n",
    "show(p)  # open a browser"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4e1c5285",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df['date'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b9d5245",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
